package md.lanjing.com.module_deal_center.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lxh.baselibray.util.TimeUtils;

import java.util.List;

import md.lanjing.com.module_deal_center.R;
import md.lanjing.com.module_deal_center.bean.BuyOrderStateResponce;
import md.lanjing.com.module_deal_center.ui.activity.PayMoneyActivity;


public class BuyOrderStateAdapter extends BaseQuickAdapter<BuyOrderStateResponce.DataBean,BaseViewHolder> {
    int type;
    public BuyOrderStateAdapter(int layoutResId, @Nullable List<BuyOrderStateResponce.DataBean> data) {
        super(layoutResId, data);
    }

    public void setType(int type) {
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, BuyOrderStateResponce.DataBean item) {
        helper.setText(R.id.tv_buy_id,"寄售人ID："+item.getOwner())
                .setText(R.id.tv_order_number,"订单号："+item.getTransferBillLog().getBillId())
                .setText(R.id.tv_buy_number,"CAWD".equals(item.getType())?"购买CAWD数量："+item.getTransferBillLog().getTokenNum():"购买USDT数量："+item.getTransferBillLog().getTokenNum())
                .setText(R.id.tv_per_price,"单价："+item.getCnyPrice()+"CNY")
                .setText(R.id.tv_total_num,"购买总价"+Double.valueOf(item.getCnyPrice())*Double.valueOf(item.getTransferBillLog().getTokenNum())+"CNY");

        TextView tvCountDown=helper.getView(R.id.tv_count_down);
        TextView tvOrderTime=helper.getView(R.id.tv_order_time);
        TextView tvPay=helper.getView(R.id.tv_pay_money);
        ImageView ivFinish=helper.getView(R.id.iv_finish);

        if (type==1){
            ivFinish.setVisibility(View.GONE);
            tvCountDown.setText(item.getRemainingTime());
            tvOrderTime.setText(TimeUtils.millis2String(Long.parseLong(item.getTransferBillLog().getLockTime())));
            tvPay.setVisibility(View.VISIBLE);
            tvPay.setOnClickListener(v -> {
                Intent intent = new Intent(mContext, PayMoneyActivity.class);
                intent.putExtra(PayMoneyActivity.TRANSFER_ID,item.getTransferBillLog().getId());
                mContext.startActivity(intent);
            });
        }else if (type==2){
            ivFinish.setVisibility(View.GONE);
            tvCountDown.setText(item.getRemainingTime());
            tvOrderTime.setText(TimeUtils.millis2String(Long.parseLong(item.getTransferBillLog().getBuyTime())));
            tvPay.setVisibility(View.GONE);
        }else if (type==3){
            ivFinish.setVisibility(View.VISIBLE);
            tvCountDown.setVisibility(View.GONE);
            tvOrderTime.setText(TimeUtils.millis2String(Long.parseLong(item.getTransferBillLog().getConfirmTime())));
            tvPay.setVisibility(View.GONE);
        }

    }
}
